home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 49 / Amiga Format CD49 (2000-01-17)(Future Publishing)(GB)(Track 1 of 3)[!][issue 2000-02].iso / -websites- / wirenet / files / wirenet15.lzx / Updates / Connect next >
Text File  |  1999-11-06  |  9KB  |  279 lines

  1. /* $VER: Connect 1.5  (01.09.96) (c) Neil Bothwick */
  2. /*                                                 */
  3. /* Connects your Amiga to the Internet, optionally */
  4. /* fetching news or mail and logging off again     */
  5. /* :
  6.     Name
  7.         Connect
  8.  
  9.     Usage
  10.         Connect [MAIL|NEWS|AUTOMAIL|AUTONEWS|OFF|AUTOOFF]
  11.  
  12.     Options
  13.         None:       Connects to Internet
  14.         MAIL:       Connects to Internet and fetches mail
  15.         NEWS:       Connects to Internet and fetches news and mail
  16.         AUTOMAIL:   Connects to Internet, fetches mail and disconnects
  17.         AUTONEWS:   Connects to Internet, fetches news and mail and disconnects
  18.         OFF:        Disconnects from Internet
  19.         AUTOOFF:    Disconnects from Internet after waiting for news and mail to finish
  20.  
  21. */
  22. ;;
  23. /* :These are specific to your setup */
  24.  
  25. DevName    = 'DEVS:Networks/ppp.device'                             /* Your network device */
  26. DevUnit    = 0                                                      /* its unit number */
  27. Interface  = 'ppp'||DevUnit                                         /* Interface name */
  28. ;;
  29. /* :Don't change anything below here */
  30.  
  31. if ~show('L','rexxsupport.library') then                            /* Load the libraries */
  32.     if ~addlib('rexxsupport.library',0,-30) then exit
  33.  
  34. if ~show('L','rexxdossupport.library') then
  35.     if ~addlib('rexxdossupport.library',0,-30) then exit
  36.  
  37. if ~show('L','rexxreqtools.library') then
  38.     if ~addlib('rexxreqtools.library',0,-30) then exit
  39.  
  40. BinPath    = 'AmiTCP:bin/'                                          /* Paths to AmiTCP commands */
  41. ThorPath   = GetVar('Thor/ThorPath')
  42. Miami      = 'AmiTCP:Miami'
  43. StartNet   = BinPath||'StartNet'
  44. ifconfig   = BinPath||'ifconfig'
  45. route      = BinPath||'route'
  46. online     = BinPath||'online'
  47. offline    = BinPath||'offline'
  48. resolve    = BinPath||'resolve'
  49. SendEvents = BinPath||'SendEvents'
  50. GetMail    = BinPath||'Fetch Mail'
  51. GetNews    = BinPath||'Fetch All'
  52. LogPath    = 'UUSpool:Connect.log'
  53. SendProc   = ThorPath||'bin/SendTCP'                                /* CLI process names for news and mail */
  54. GetProc    = ThorPath||'bin/GetTCP'
  55. Unbatch    = BinPath||'ParseThor'
  56. ;;
  57. options results
  58. address command
  59. arg opt
  60.  
  61. /* :Main routine */
  62. if exists('ENV:Wirenet/UseMiami') then UseMiami = 1
  63. else UseMiami = 0
  64.  
  65. select
  66.     when opt = '' then call Connect
  67.     when opt = 'MAIL' then do
  68.         call Connect
  69.         call DoMail
  70.         end
  71.     when opt = 'NEWS' then do
  72.         call Connect
  73.         call DoNews
  74.         end
  75.     when opt = 'AUTOMAIL' then do
  76.         call Connect
  77.         call DoMail
  78.         call Auto
  79.         call Disconnect
  80.         end
  81.     when opt = 'AUTONEWS' then do
  82.         call Connect
  83.         call DoNews
  84.         call Auto
  85.         call Disconnect
  86.         end
  87.     when opt = 'OFF' then call Disconnect
  88.     when opt = 'AUTOOFF' then do
  89.         call Auto
  90.         call Disconnect
  91.         end
  92.     otherwise call BadArgs
  93.     end
  94. ;;
  95. exit
  96.  
  97. /* Procedures */
  98.  
  99. /* :Establish connection */
  100. Connect:
  101.     StartNet
  102.     if exists('AmiTCP:db/User-PreConnect') then address command 'AmiTCP:db/User-PreConnect'
  103.     if UseMiami = 0 then do
  104.         call MakeDialScript()
  105.         online Interface
  106.         if RC > 0 then call ConnectionFailed
  107.         ifconfig 'lo0 localhost'
  108.         ifconfig Interface '$ppp0IPLocal $ppp0IPRemote'
  109.         route 'add default $ppp0IPRemote'
  110.         call WriteLog('Connection made to' GetVar('ppp0IPRemote'))
  111.         end
  112.     else do
  113.         address 'MIAMI.1' 'ONLINE'
  114.         address 'MIAMI.1' 'ISONLINE'
  115.         if RC = 0 then call ConnectionFailed
  116.         call WriteLog('Connection made')
  117.         end
  118.     'SetEnv NetState Online'
  119.     if exists('AmiTCP:db/User-PostConnect') then address command 'AmiTCP:db/User-PostConnect'
  120.     'run >NIL:' SendEvents
  121.     Wait 2
  122.     return
  123. ;;
  124. /* :Break connection */
  125. Disconnect:
  126.     if exists('AmiTCP:db/User-PreDisconnect') then address command 'AmiTCP:db/User-PreDisconnect'
  127.     if UseMiami = 0 then do
  128.         ifconfig interface 'down'
  129.         offline Interface
  130.         route 'delete >NIL: $ppp0IPLocal'
  131.         route 'delete >NIL: default'
  132.         end
  133.     else do
  134.         address 'MIAMI.1' 'OFFLINE'
  135.         end
  136.     call WriteLog('Connection closed')
  137.     'unsetenv FetchState'
  138.     'SetEnv NetState Offline'
  139.     Unbatch
  140.     if exists('AmiTCP:db/User-PostDisconnect') then address command 'AmiTCP:db/User-PostDisconnect'
  141.     return
  142. ;;
  143. /* :Start mail download */
  144. DoMail:
  145.     'run >NIL:' GetMail
  146.     call WriteLog('Mail download started')
  147.     return
  148. ;;
  149. /* :Start mail and news download */
  150. DoNews:
  151.     'Run >NIL:' GetNews
  152.     call WriteLog('News download started')
  153.     return
  154. ;;
  155. /* :Wait for mail and news processes to stop */
  156. Auto:
  157.     say 'Waiting for news/mail to finish'
  158.     call WaitToEnd(SendProc GetProc)
  159.     Wait 2
  160.     call WaitToEnd(SendProc GetProc 'ncftp' 'AmiTCP:bin/ncftp')
  161.     return
  162. ;;
  163. /* :Give usage information */
  164. BadArgs:
  165.     say
  166.     say 'Usage: Connect [MAIL|NEWS|AUTOMAIL|AUTONEWS|OFF|AUTOOFF]'
  167.     say
  168.     say '       None:       Connects to Internet'
  169.     say '       MAIL:       Connects to Internet and fetches mail'
  170.     say '       NEWS:       Connects to Internet and fetches news and mail'
  171.     say '       AUTOMAIL    Connects to Internet, fetches mail and disconnects'
  172.     say '       AUTONEWS:   Connects to Internet, fetches news and mail and disconnects'
  173.     say '       OFF:        Disconnects from Internet'
  174.     say '       AUTOOFF:    Disconnects from Internet after waiting for news and mail to finish'
  175.     say
  176.     exit
  177.  ;;
  178. /* :Write line in logfile */
  179. WriteLog: procedure expose LogPath
  180.     parse arg msg
  181.     LogEntry = left(date('W'),3) date() time() msg
  182.     say LogEntry
  183.     if ~open(log,LogPath,'A') then do
  184.         if ~open(log,LogPath,'W') then return
  185.         end
  186.     call writeln(log,LogEntry)
  187.     call close(log)
  188.     return
  189. ;;
  190. /* :Wait for the specified process to finish */
  191. WaitToEnd: procedure
  192.     parse arg Processes
  193.  
  194.     procs = words(Processes)
  195.     do i = 1 to procs
  196.         parse var Processes Process.i Processes
  197.         end
  198.  
  199.     do until Busy = FALSE
  200.         Busy = FALSE
  201.         do i = 1 to procs
  202.             'Status >NIL: com='Process.i
  203.             if RC = 0 then do
  204.                 Busy = TRUE
  205.                 Wait 3
  206.                 end
  207.             end
  208.         end
  209.     return
  210. ;;
  211. /* :Report connection failure */
  212. ConnectionFailed:
  213.     call WriteLog('Connection attempt failed')
  214.     ExitMsg('Your internet connection has failed')
  215.     return
  216. ;;
  217. /* :Exit with message */
  218. ExitMsg:
  219.     parse arg ErrMsg
  220.     say(ErrMsg)
  221.     exit
  222.     return
  223. ;;
  224. /* :Create dialscript and ppp0.config */
  225. MakeDialScript:
  226.     /* Create DialScript */
  227.     if ~open('ds','ENV:Wirenet/DialScript','W') then call ExitMsg('Failed to create dialscript')
  228.     call writeln('ds','# Dialer Script (change to echo off if you do not want echoing)')
  229.     call writeln('ds','echo on')
  230.     call writeln('ds','abort "NO DIALTONE"')
  231.     call writeln('ds','redial "BUSY" "NO CARRIER" "NO ANSWER"')
  232.     call writeln('ds','redialdelay 300')
  233.     call writeln('ds','timeout 500')
  234.     call writeln('ds','# Initialise modem...')
  235.     call writeln('ds','send "'||GetVar('Wirenet/ModemInit')||'"')
  236.     call writeln('ds','wait "OK"')
  237.     call writeln('ds','delay 15')
  238.     call writeln('ds','# Send dial command...')
  239.     call writeln('ds','send "'||GetVar('Wirenet/ModemDial')||GetVar('Wirenet/PoPNum')||'"')
  240.     call writeln('ds','# ... and wait for connection.')
  241.     call writeln('ds','timeout 1600')
  242.     call writeln('ds','wait "CONNECT"')
  243.     if ~exists('ENV:Wirenet/UsePAP') then do
  244.         call writeln('ds','send ""')
  245.         call writeln('ds','# At login: prompt send nodename')
  246.         call writeln('ds','wait "ogin:"')
  247.         call writeln('ds','send "'||GetVar('NODENAME')||'"')
  248.         call writeln('ds','# At Password: prompt send password')
  249.         call writeln('ds','wait "assword:"')
  250.         call writeln('ds','echo off')
  251.         call writeln('ds','send "'||subword(GetVar('Wirenet/pap.config'),2)||'"')
  252.         call writeln('ds','echo on')
  253.         call writeln('ds','# Wait for Service: prompt and then send PPP')
  254.         call writeln('ds','wait "ervice:"')
  255.         call writeln('ds','send "PPP"')
  256.         call writeln('ds','# Wait for start string')
  257.         call writeln('ds','wait "MTU"')
  258.         call writeln('ds','send " "')
  259.         call writeln('ds','# Connected!')
  260.         end
  261.     call close('ds')
  262.  
  263.     /* Create PPP config file */
  264.     if ~open(pppcfg,'ENV:sana2/ppp0.config','w') then ExitMsg('Failed to create ppp configuration')
  265.     call writech(pppcfg,GetVar('Wirenet/ModemDev')' ')
  266.     call writech(pppcfg,GetVar('Wirenet/ModemSpeed')' ')
  267.     call writech(pppcfg,GetVar('IPADDRESS')' ')
  268.     call writech(pppcfg,'DialScript ENV:Wirenet/DialScript ')
  269.     call writech(pppcfg,'MTU='GetVar('Wirenet/MTU')' ')
  270.     call writeln(pppcfg,GetVar('Wirenet/ppp.options')' ')
  271.     if exists('ENV:Wirenet/UsePAP') then call writech(pppcfg,'PAP=ENV:Wirenet/pap.config,wirenet ')
  272.     if exists('ENV:Wirenet/DialWindow') then call writech(pppcfg,'DIALWINDOW ' GetVar('Wirenet/DialWindow')' ')
  273.     if exists('ENV:Wirenet/Gateway') then call writech(pppcfg,'REMOTEIP ' GetVar('Wirenet/Gateway')' ')
  274.     call close(pppcfg)
  275.  
  276.     return
  277. ;;
  278.  
  279.